package com.example.JavaConcurrent.Project2_CountDownLatchAndCyclicBarrier.CyclicBarrierBegin_5;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class MyThread  extends Thread{
    private CyclicBarrier cbRef;

    public MyThread(CyclicBarrier cbRef){
        super();
        this.cbRef = cbRef;
    }

    @Override
    public void run() {
        try{

            System.out.println(Thread.currentThread().getName() + " begin1-Time="+System.currentTimeMillis());
            if(Thread.currentThread().getName().equals("t2")){
                System.out.println("t2 进入");
                Thread.sleep(5000);
                //Integer.parseInt("t");//一个报错，其他等待，不影响主流程
                Thread.currentThread().interrupt();//一个线程中断或离开屏障，其他线程也会离开屏障点
            }
            cbRef.await();
            System.out.println(Thread.currentThread().getName() + " end1-Time="+System.currentTimeMillis());

         }catch (InterruptedException e){

        }catch (BrokenBarrierException e){

        }
    }
}
